#include "threadpool.h"

int initQueue(taskQueue_t *pqueue){
    bzero(pqueue,sizeof(taskQueue_t));
    pthread_mutex_init(&pqueue->mutex,NULL);
    pthread_cond_init(&pqueue->cond,NULL);
    return 0;
}

int enQueue(taskQueue_t *pqueue, int netfd){
    task_t* pnew=(task_t*)calloc(1,sizeof(task_t));
    pnew->netfd=netfd;
    pnew->next=NULL;
    if(pqueue->queueSize==0){
        pqueue->head=pnew;
        pqueue->tail=pnew;
    }else{
        pqueue->tail->next=pnew;
        pqueue->tail=pnew;
    }
    ++pqueue->queueSize;
    return 0;
}

int deQueue(taskQueue_t *pqueue){
    task_t*pcurr=pqueue->head;
    pqueue->head=pqueue->head->next;
    if(pqueue->queueSize==1){
        pqueue->tail=NULL;
    }
    free(pcurr);
    --pqueue->queueSize;
    return 0;
}

/*int main(int argc,char* argv[])
{
    taskQueue_t taskqueue;
    initQueue(&taskqueue);
    enQueue(&taskqueue,1);
    enQueue(&taskqueue,2);
    enQueue(&taskqueue,3);
    enQueue(&taskqueue,4);
    enQueue(&taskqueue,5);
    task_t* pcurr;
    pcurr=taskqueue.head;
    while(pcurr){
        printf("%d",pcurr->netfd);
        pcurr=pcurr->next;
    }
    printf("\n");
    deQueue(&taskqueue);
    pcurr=taskqueue.head;
    while(pcurr){
        printf("%d",pcurr->netfd);
        pcurr=pcurr->next;
    }
    printf("\n");

    return 0;
}
*/
